<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>    
<%@taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="<c:url value="/resources/homepage.css" />" rel="stylesheet">
<link href="<c:url value="/resources/logo1.png" />" rel="icon" type="image/x-icon">
<title>Add Employee </title>
</head>
<script type="text/javascript">

function EditEmp(id)
{
	  window.open("Editemp.jsp?&id="+id,"Edit Story Details window", 'height=200px width=200px',false);
    //location.href("Editemp.jsp");
}

function funValid()
{
 // alert("Are you sure you want to delete the employee ?");	
var msg=confirm("Are you sure you want to delete the employee ?");
	if(msg==true);
	else
		{
			//location.href("Addemp.jsp");
		}
}

/*function fun1()
{
		//confirm("Record added successfully");	
		alert("Record added successfully...");
}*/
function fun2()
{
		var msg = confirm("Redirected to Admin form");
		if(msg ==true)
		{
			window.location.assign("Admin.jsp");	
		}
		else
		{
			;
		}
}
function fun1()
{
		var a = document.forms["myform"]["first_name"].value;
		var b = document.forms["myform"]["last_name"].value;
		var c = document.forms["myform"]["email_id"].value;
		var d = document.forms["myform"]["designation"].value;
		var e = document.forms["myform"]["password"].value;
		var f = document.forms["myform"]["confirm_password"].value;
		
		if (a == null || a == "")
		{
			alert("first name cannot be empty...");
			//return false;
		}
		if (b == null || b == "")
		{	alert("last name cannot be empty...");
			//return false;
		}
		if (c == null || c == "")
		{	
			alert("email cannot be empty...");
			//return false;
		}	
		if(c!=null || c!="")
		{
			var atpos = c.indexOf("@");
			var atlpos = c.lastIndexOf("@");
	    	var dotpos = c.lastIndexOf(".");
	    	if (atpos< 1 || dotpos<atpos+2 || dotpos+2>=c.length || atlpos!=atpos) 
	    	{
	        	alert("Not a valid e-mail address");
	        	//return false;
			}
	    	
	    	//var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    		/*if (!filter.test(c)) {
    			alert('Please provide a valid email address');
    			c.focus;
    			return false;
    		*/
		}
		if (d == null || d == "")
		{	alert("select designation...");
			//return false;
		}
		if (e == null || e == "" && f == null || f == "")
		{	alert("password cannot be empty...");
			//return false;
		}
		if (e != f)
		{	alert("password & confirm password should be same...");
			//return false;
		}
		if(a!=null && b!=null && c!=null && d!=null && e!=null && e==f)
		{
			alert("Record added successfully...");	
			//return true;
		}
}
</script>

<body>
<form:form name="myform" action="saveEmployee" method="post" modelAttribute="employee"> 
<div id="wrapper">

<!-- ============ HEADER SECTION ============== -->
		<div id="header">
			<div id="headerlogo">
				</div>
		</div>
<!-- ============ NAVIGATION SECTION ============== -->
	<div id="menubar">
		
			<ul>
			 <li><a href="Admin">Home</a></li>
			 <li><a href="Addemp">Employee</a></li>
			 <li><a href="Addrole">Role</a></li>
			 <li><a href="Platform">Platform</a></li>
 			 <li><a href="AddClient">Client</a></li>
 			 <li><a href="AddStoryPoints">Story Points</a></li>
<!--			<li><a href="#">Complexity</a></li>
			<li><a href="#">Priority</a></li>
 -->		
 			<li><a href="logout">Logout</a></li>
			</ul>
	</div>

<br>
<div id="searchbar" align="right">
<input type="text" name="q" size="125" placeholder="search..."/><input type="submit" value="search" name="login" class="buttonStyle"/>
</div>
		

<!-- 
<div id="innercontent1">

<b>
<h3>
First Name <input type="text" name="fname">
<br><br>
Email ID <input type="text" name="eid" style="width:300px">
<br><br>
Password  <input type="text" name="pswd" >


</h3>
</b>

</div>

<div id="innercontent2">
<b>
<h3>
Last Name <input type="text" name="lname">
<br><br>
Designation 
<br><br>
Confirm password  <input type="text" name="cpswd" >


</h3>
</b>

</div>
 -->
 <div id="m1">
<fieldset>
				<legend>
					<h3>Add Employee</h3>
				</legend>
 <table>

<form:hidden path="emp_id"/>

 <tr>
 <th> First Name</th> 
 <td>
 	<td><form:input path="first_name" size="30"/>
 </td>
 <th> Last Name</th> 
 <td>
 	<td><form:input path="last_name" size="30" />
 </td>
  </tr>
 
 <tr>
 <th>Email Id</th> 
 <td>
 	<td><form:input path="email_id" size="30" /></td>
 <th>Designation</th> 
 <td>
 	<td>
 		<form:select path="designation_id">
					<option value='<c:out value="${designationName.designation_id}"/>'><c:out value="${designationName.designation_name}" /></option>
							<c:forEach var="designation1" items="${designationList}">
								<option value='<c:out value="${designation1.designation_id}"/>'>
										<c:out value="${designation1.designation_name}" />
								</option>
							</c:forEach>
		</form:select>
 	</td>
 </td>
 </tr>
 
 <tr>
 <th>Password</th> 
 <td>
 	<td><form:input path="password" size="30" />
 </td>
 <th>Confirm password</th> 
 <td>
 	<td><form:input path="confirm_password" size="30" /></td>
 </td>
  </tr>
  
</table> 
<br>
<input type="reset" value="RESET" style="margin-left: 390px; width: 70px; height: 30px" /> 
<input type="submit" value="ADD" style="margin-left:50px; width: 70px; height: 30px" onclick="fun1()" />
<input type="button" value="CANCEL" style="margin-left:50px; width: 70px; height: 30px" onclick="fun2()" />

</fieldset>
</div>

<div id="main">
<center>
<br><br><br>
<div id="scroller">
<table>
<tr>
<th>Employee ID</th>
<th>Employee Name</th>
<th>Employee Username</th>
<th>Designation</th>
<!-- <th>Role</th> -->
<th>Action</th>
</tr>
<!--<c:forEach var="user" items="${listEmployee}" varStatus="status">
	<tr>
		<td>${status.index + 1}</td>
		<td>${user.first_name} ${user.last_name}</td>
		<td>${user.email_id}</td>
		<td>${user.designation_name}</td>
<%-- 		<td>${user.role_name}</td> --%>
		<td>     
       		<a href="editEmployee?id=${user.id}">Edit</a>
			&nbsp;&nbsp;&nbsp;&nbsp;
			<a href="deleteEmployee?id=${user.id}">Delete</a>
       	</td>
	</tr>
</c:forEach>
-->
		<sql:setDataSource
				var="myDS"
				driver="com.mysql.jdbc.Driver"
				url="jdbc:mysql://localhost:3306/springct"
				user="root" 
				password="dhanashree"	/>

		<sql:query var="employee"	dataSource="${myDS}">
		select employee.emp_id, first_name, last_name, email_id, designation_name from employee,designation where employee.designation_id=designation.designation_id;
		</sql:query>

		 <c:forEach var="employee" items="${employee.rows}" >
		 	<tr>
		 		<td>${employee.emp_id }</td>
		 		<td>${employee.first_name} ${employee.last_name}</td>
		 		<td>${employee.email_id}</td>
		 		<td>${employee.designation_name }</td>
		 		<td>     
       				<a href="EmpForm?id=${employee.emp_id}">Edit</a>
					&nbsp;&nbsp;&nbsp;&nbsp;
					<a href="deleteEmployee?id=${employee.emp_id}">Delete</a>
       			</td>	
		 	</tr>
		 </c:forEach>			

         </table>
         </div>
      </center>
</div>

 	
	<div id="footer">
	<p>Copyright &copy; 2014 - All Rights Reserved - Spring Computing Pvt. Ltd.</p>
	</div>
</div> 
</form:form>
</body>
</html>